package com.tbi.graphcolouring.testers;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Map;
import java.util.TreeMap;

import javax.swing.JFrame;
import javax.swing.border.EmptyBorder;

import com.tbi.graphcolouring.utils.Random;

@SuppressWarnings("serial")
public class RandomTest extends JFrame {

	private StatisticsPanel contentPane;
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		final Map<Integer, Integer> randomCounter = new TreeMap<>();
		
		for(int i=0; i<1000000; i++){
			int randomNumber = (int)(Random.scaledGaussian(1000));
//			int randomNumber = (int)(Random.scaledExponential(1000));
			if(randomCounter.containsKey(randomNumber)){
				int temp = randomCounter.get(randomNumber);
				temp++;
				randomCounter.put(randomNumber, temp);
			}else{
				randomCounter.put(randomNumber, 1);
			}
		}
		
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					RandomTest frame = new RandomTest(randomCounter);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 * @param randomCounter 
	 */
	public RandomTest(Map<Integer, Integer> randomCounter) {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(10, 10, 1300, 700);
		contentPane = new StatisticsPanel(randomCounter);
		contentPane.setBackground(Color.WHITE);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		addKeyListener(new KeyListener() {
			public void keyTyped(KeyEvent arg0) { } 
			public void keyReleased(KeyEvent arg0) { }
			
			@Override
			public void keyPressed(KeyEvent e) {
				if(e.getKeyCode() == KeyEvent.VK_ESCAPE){
					System.exit(0);
				}
			}
		});
	}

}
